<?php

namespace mpend\modules\app\controllers;

use Yii;
use mpend\components\Controller;
use common\helpers\Url;
use common\helpers\ArrayHelper;
use common\models\app\AppVersion;

/**
 * 下载APP
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class DownloadController extends Controller {

    public $closeCheckAuthent = true;

    /**
     * {@inheritdoc}
     */
    protected function verbs() {
        return [
            '*' => ['GET'],
        ];
    }

    /**
     * 下载APP
     * @inheritdoc
     */
    public function actionIndex() {
        $device = Yii::$app->request->get('device');
        $data = [
            'title' => '若您未安装优越定制APP',
            'image' => Url::attach('assets/cover/downbg.png'),
        ];
        $version = AppVersion::getLatest();
        $downloadLink = $version ? $version->link : Url::attach('download/yydz-release.apk');
        $deviceList = [
            'ios' => [
                'link' => 'https://apps.apple.com/cn/app/id1435853204',
                'text' => '去App Store下载',
            ],
            'android' => [
                'link' => $downloadLink,
                'text' => '立即下载',
            ],
        ];
        $current = ArrayHelper::getValue($deviceList, $device);
        if ($current) {
            $data[$device] = $current;
        } else {
            $data = ArrayHelper::merge($data, $deviceList);
        }
        return $data;
    }

}
